using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
namespace MicroMsg.Storage
{
	public class TimeLineObject : TloXmlItem
	{
		private const string TAG = "TimeLineObject";
		public ulong nID;
		public string strUsername;
		public string strNickName;
		public uint nCreateTime;
		public int nPrivate;
		public string strContentDesc;
		public ContentObject content;
		public TloLocation tloLocation_0;
		public static TimeLineObject ParseFrom(byte[] bytesXmlData)
		{
			TimeLineObject timeLineObject = new TimeLineObject();
			if (timeLineObject.Parse(bytesXmlData))
			{
				return timeLineObject;
			}
			return null;
		}
		public bool Parse(byte[] bytesXmlData)
		{
			if (bytesXmlData == null)
			{
				return false;
			}
			try
			{
				XDocument xDocument = XDocument.Load(new MemoryStream(bytesXmlData));
				bool result;
				if (xDocument.get_Root().get_Name() != "TimelineObject")
				{
					Log.smethod_1("TimeLineObject", "error object name=" + xDocument.get_Root().get_Name());
					result = false;
					return result;
				}
				using (IEnumerator<XElement> enumerator = xDocument.get_Root().Elements().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						XElement current = enumerator.get_Current();
						if (!current.get_IsEmpty() || current.get_HasAttributes())
						{
							if (current.get_Name() == "id")
							{
								this.nID = (ulong)current;
							}
							else
							{
								if (current.get_Name() == "username")
								{
									this.strUsername = (string)current;
								}
								else
								{
									if (current.get_Name() == "createTime")
									{
										this.nCreateTime = (uint)current;
									}
									else
									{
										if (current.get_Name() == "private")
										{
											this.nPrivate = (int)current;
										}
										else
										{
											if (current.get_Name() == "contentDesc")
											{
												this.strContentDesc = (string)current;
											}
											else
											{
												if (current.get_Name() == "ContentObject")
												{
													this.content = new ContentObject(current);
												}
												else
												{
													if (current.get_Name() == "location")
													{
														this.tloLocation_0 = new TloLocation(current);
													}
													else
													{
														Log.smethod_4("TimeLineObject", "unknown timeobject tag" + current.get_Name());
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
				result = true;
				return result;
			}
			catch (Exception ex)
			{
				Log.smethod_1("TimeLineObject", "xml parse error=" + ex);
			}
			return false;
		}
		public XElement toXElement()
		{
			XElement xElement = new XElement("TimelineObject");
			xElement.Add(new XElement("id", this.nID));
			xElement.Add(new XElement("username", this.strUsername));
			xElement.Add(new XElement("createTime", this.nCreateTime));
			xElement.Add(new XElement("private", this.nPrivate));
			xElement.Add(new XElement("contentDesc", this.strContentDesc));
			if (this.content != null)
			{
				xElement.Add(this.content.toXElement());
			}
			if (this.tloLocation_0 != null)
			{
				xElement.Add(this.tloLocation_0.toXElement());
			}
			return xElement;
		}
		public byte[] toXmlData()
		{
			MemoryStream memoryStream = new MemoryStream();
			XElement xElement = this.toXElement();
			xElement.Save(memoryStream);
			return memoryStream.ToArray();
		}
		public static void dumpXmlData(byte[] bytesXmldata)
		{
		}
	}
}
